#!/bin/bash

game_saved_dir=$HOME/Steam/steamapps/common/PalServer/Pal/Saved
game_saved_backup_dir=$HOME/palbackup

while [ $# -gt 0 ]; do
  case $1 in
    --game-saved-dir)
      game_saved_dir=$2
      shift
      shift
      ;;
    --game-saved-backup-dir)
      game_saved_backup_dir=$2
      shift
      shift
      ;;
    *)
      echo "Unknown argument: $1"
      exit 1
      ;;
  esac
done

if [ ! -d $game_saved_dir ]; then
    echo "$game_saved_dir not exist"
    exit 1
fi

if [ ! -d $game_saved_backup_dir ]; then
    mkdir -p $game_saved_backup_dir
fi

backup_time=$(date +%Y%m%d_%H%M%S)
backup_filename=${backup_time}.tgz

cd $game_saved_dir/../
tar zcvf $backup_filename Saved
mv $backup_filename $game_saved_backup_dir

echo "backup game saved to ${game_saved_backup_dir}/${backup_filename}"
